﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Bluebunnie
{
	/// <summary>
	/// Interaction logic for Login.xaml
	/// </summary>
	public partial class Login : Window
	{
        public Login()
		{
			this.InitializeComponent();

            Closed += (sender, e) => { DialogResult = false; };
			// Insert code required on object creation below this point.
		}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string userstring = string.Empty;
            try
            {
                userstring = DataManager.GetValue("select password from tbl_user where username=@username and password=@password",
                    new Parameter("@username", txtUser.Text),
                    new Parameter("@password", txtPass.Password)).ToString();
            }
            catch
            {
                MessageBox.Show("Tidak dapat terhubung ke server. Periksa kembali pengaturan server anda.", "Oops", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            if (txtPass.Password.Equals(userstring))
                DialogResult = true;
            else
                MessageBox.Show("Username atau password salah.", "Oops", MessageBoxButton.OK, MessageBoxImage.Exclamation);
             
        }

        private void Batal_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
              
	}
}